package com.cta.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageProducer {

	private static final Logger LOG = LoggerFactory
			.getLogger(MessageProducer.class);

	protected JmsTemplate jmsTemplate;
	

	public void sendMessages(final String payload) throws JMSException {

		jmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {

				TextMessage message = session.createTextMessage(payload);
				return message;

			}

		});

	}
	
	public void sendMessages(final String type, final String employee, final String payload) throws JMSException {
		jmsTemplate.send(new MessageCreator() {

			public Message createMessage(Session session) throws JMSException {
				Message message = session.createTextMessage(payload);
				message.setStringProperty("type", type);
				message.setStringProperty("employee", employee);
				return message;
			}
		});
	}
	
	public void sendCallLogMessages(final String employee, final String payload) throws JMSException {
		jmsTemplate.send(new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				Message message = session.createTextMessage(payload);
				message.setStringProperty("type", "call");
				message.setStringProperty("employee", employee);
				return message;
			}
		});
	}
	
	public void sendConsoleLogMessages(final String employee, final String payload) throws JMSException {
		jmsTemplate.send(new MessageCreator() {
			public Message createMessage(Session session) throws JMSException {
				Message message = session.createTextMessage(payload);
				message.setStringProperty("type", "console");
				message.setStringProperty("employee", employee);
				return message;
			}
		});
	}


	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}
}
